Skip to content

Simplify Makefile and tool installations#355

Closed
xrstf wants to merge 4 commits into
kbind-dev:mainfrom
xrstf:uget
Closed

Simplify Makefile and tool installations#355
xrstf wants to merge 4 commits into
kbind-dev:mainfrom
xrstf:uget

Conversation

@xrstf

@xrstf xrstf commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Summary

This introduces µget to download build tools and replace the go-install.sh. µget is better because it can download prebuilt binaries and handles checksums to detect malicious upstream changes. For a developer, nothing really changes in the workflows ("make lint" works just as before), only when you update a tool will you have to run UGET_UPDATE=true make ....... to make µget update all checksums.

Besides this, this PR also performs some general cleanup to our Makefiles:

  • no more seemingly unused mktemp -d for each make invocation
  • GOBIN_DIR was renamed to BUILD_DIR, because TOOLS_GOBIN_DIR was confusing. Now it's TOOLS_DIR and BUILD_DIR, plus their ABS_... variants.
  • The INSTALL_GOBIN logic was removed, since it was also unused.
  • Build tools are no longer installed into bin/, but into hack/tools/, clearly separating them from our own build artifacts.
  • The tools.go was thinned out a lot. Since we already, even before this PR, installed most these tools using a fake module with versions sourced from our Makefile, having synthetic Go dependencies in kube-bind makes no sense (it would only make sense if somewhere we did an unversioned go install k8s.code-generator/cmd/lister-gen) except for the kube codegen where we refer to its kube_codegen.sh by go listing the module.
  • make clean was added to remove BUILD_DIR and TOOLS_DIR.

What Type of PR Is This?

/kind cleanup

Release Notes

NONE

Summary by CodeRabbit

  • Chores

    • Centralized build and tool outputs into dedicated build/tool directories, added clean target, and adjusted build/install flows.
    • Introduced a guarded downloader with checksum verification and manifest, removed the legacy Go installer, and switched tool acquisition to the new downloader or clone-and-build flows; removed several now-unused module dependencies.
  • Documentation

    • Bumped Go requirement to 1.24+, renamed quickstart title to "kube-bind", and updated setup docs to use the new make-based tool build/start workflow and clarified local setup steps.

@coderabbitai

coderabbitai Bot commented Nov 3, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Refactors build tooling to use ABS_BUILD_DIR/ABS_TOOLS_DIR, adds a new downloader script (hack/uget.sh) with checksum support, replaces many go-installs with uget fetches, removes hack/go-install.sh, updates tool wiring and go.mod, and adjusts docs and Makefiles for Dex and Go version changes.

Changes

Cohort / File(s) Summary
Top-level Makefile & build paths
Makefile
Replace GOBIN/GOPATH usage with ABS_BUILD_DIR / ABS_TOOLS_DIR; reorder PATH; switch tool resolution to build/tool dirs; update build/install/clean targets to output to ABS_BUILD_DIR; convert many go install calls to use hack/uget.sh.
Contrib kcp Makefile
contrib/kcp/Makefile
Replace GOPATH/GOBIN logic with ABS_TOOLS_DIR/ABS_BUILD_DIR; export UGET_DIRECTORY and UGET_CHECKSUMS; switch go-installs to uget fetches; export KCP apigen tool path.
Tool acquisition & checksums
hack/uget.sh (new), hack/tools.checksums (new), hack/go-install.sh (deleted)
Introduce uget downloader with URL placeholders, checksum verification, update mode, and Go-module-aware flows; add static checksums file; remove legacy hack/go-install.sh.
Tool wiring
hack/tools.go
Remove several tool imports (cluster-client-gen, apigen, conversion-gen, deepcopy-gen, defaulter-gen, controller-gen), leaving only k8s.io/code-generator.
Module dependencies
go.mod
Remove multiple tool/dependency requires (including kcp code-generator, controller-tools, color/flect/mattn/logrus, yaml.v2).
Documentation updates
docs/content/contributing/index.md, docs/content/setup/kcp-setup.md, docs/content/setup/quickstart.md, docs/content/setup/local-setup-with-kind.md, docs/content/setup/.pages
Bump Go requirement to 1.24+; change Dex instructions to use make dex and ./hack/tools/dex serve; update quickstart title/wording and cluster prerequisite notes; reformat and renumber steps; add kcp-setup to docs nav.

Sequence Diagram(s)

sequenceDiagram
    participant Make as Makefile
    participant UGET as hack/uget.sh
    participant Net as Network
    participant CS as hack/tools.checksums
    participant Tools as ABS_TOOLS_DIR

    rect rgb(248,248,255)
    Note over Make,UGET: New tool fetch flow
    Make->>UGET: request tool + version + params
    UGET->>Net: resolve & download artifact URL
    Net-->>UGET: binary/archive
    UGET->>CS: lookup expected checksum
    CS-->>UGET: checksum
    UGET->>UGET: verify checksum
    alt checksum matches
        UGET->>Tools: place binary
        Tools-->>Make: tool available
    else checksum mismatch
        UGET-->>Make: error (checksum mismatch)
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Pay extra attention to:
    • hack/uget.sh (complex Bash logic, placeholder and checksum handling)
    • Makefile PATH and tool resolution changes
    • contrib/kcp/Makefile exports and tool path usages
    • go.mod removals to ensure no residual references

Possibly related PRs

  • KCP e2e test #333 — modifies contrib/kcp tooling and Dex/KCP provisioning, closely related to Makefile and docs changes.
  • Update docs for v0.5 #324 — updates KCP/Dex build & run instructions in docs, related to quickstart and setup edits.

Suggested reviewers

  • mjudeikis
  • ntnn
  • kmk142789

Poem

Tools now live in new dirs, checksums kept in line,
uget fetches, verifies, then places each design.
Makefiles point to hack/tools, docs note Go's new day,
builds land in ABS_BUILD_DIR — tidy, clear, and fey.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes in the PR: introducing µget for simplified tool installation and performing Makefile cleanup.
Description check ✅ Passed The description provides a comprehensive summary, specifies the PR kind as cleanup, and follows the repository template structure with all required sections completed.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d3e521 and fda1111.

📒 Files selected for processing (1)
  • docs/content/setup/.pages (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/content/setup/.pages
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: lint
  • GitHub Check: verify
  • GitHub Check: go-test
  • GitHub Check: go-test-e2e

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xrstf xrstf force-pushed the uget branch 4 times, most recently from 965c132 to 9eaa7b0 Compare November 3, 2025 15:49
@xrstf xrstf marked this pull request as ready for review November 3, 2025 16:51
@xrstf xrstf requested a review from a team as a code owner November 3, 2025 16:51
@xrstf

xrstf commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
Makefile (2)

20-20: Consider removing trailing slash from BUILD_DIR for consistency.

Line 20 defines BUILD_DIR=bin/ with a trailing slash, but most usages in the Makefile assume no trailing slash (e.g., $(ABS_BUILD_DIR)/$(KUBE_CLIENT_GEN_BIN)). While this may work due to path normalization, removing the trailing slash would improve consistency.

Apply this diff:

-BUILD_DIR=bin/
+BUILD_DIR=bin

269-278: Consider improving error handling in dex build process.

Line 275 uses || true to ignore git clone errors, which could mask legitimate failures (network issues, permissions). The intent appears to be allowing re-runs, but this also hides real errors. Consider checking if the directory exists before cloning, or removing the directory first.

Apply this diff for better error handling:

 DEX_TMP_DIR = $(TOOLS_DIR)/dex-clone-$(DEX_VER)
 $(DEX):
 	mkdir -p $(TOOLS_DIR)
-	git clone --branch $(DEX_VER) --depth 1 https://github.com/dexidp/dex $(DEX_TMP_DIR) || true
+	rm -rf $(DEX_TMP_DIR)
+	git clone --branch $(DEX_VER) --depth 1 https://github.com/dexidp/dex $(DEX_TMP_DIR)
 	cd $(DEX_TMP_DIR) && GOWORK=off make build
 	cp -a $(DEX_TMP_DIR)/bin/dex $(DEX)
 	rm -rf $(DEX_TMP_DIR)
hack/uget.sh (1)

317-320: GOBIN setting may be redundant in Go build command.

Line 320 sets GOBIN=$(realpath .) but then uses the -o "$BINARY" flag which explicitly specifies the output location. The GOBIN setting may be unnecessary since -o takes precedence.

Consider simplifying:

-    GOFLAGS=-trimpath GOARCH="$arch" GOOS="$os" GOBIN=$(realpath .) $UGET_GO_BUILD_CMD -o "$BINARY" "$url"
+    GOFLAGS=-trimpath GOARCH="$arch" GOOS="$os" $UGET_GO_BUILD_CMD -o "$BINARY" "$url"
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f026310 and cb15ddc.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (10)
  • Makefile (10 hunks)
  • contrib/kcp/Makefile (2 hunks)
  • docs/content/contributing/index.md (1 hunks)
  • docs/content/setup/kcp-setup.md (2 hunks)
  • docs/content/setup/quickstart.md (3 hunks)
  • go.mod (0 hunks)
  • hack/go-install.sh (0 hunks)
  • hack/tools.checksums (1 hunks)
  • hack/tools.go (0 hunks)
  • hack/uget.sh (1 hunks)
💤 Files with no reviewable changes (3)
  • hack/go-install.sh
  • hack/tools.go
  • go.mod
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-12T09:05:29.762Z
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 295
File: sdk/client/listers/kubebind/v1alpha2/boundschema.go:46-48
Timestamp: 2025-09-12T09:05:29.762Z
Learning: In the kube-bind project, lister-gen is generating BoundSchema listers with singular resource names ("boundschema") instead of plural ("boundschemas"), which breaks client-go conventions and can cause cache lookup issues. This is identified as a generator issue that needs upstream investigation rather than manual code fixes.

Applied to files:

  • docs/content/setup/quickstart.md
🪛 checkmake (0.2.2)
Makefile

[warning] 134-134: Target body for "build" exceeds allowed length of 5 (6).

(maxbodylength)

🔇 Additional comments (17)
docs/content/setup/quickstart.md (1)

3-3: LGTM! Documentation updates align with new build structure.

The changes correctly reflect the new tool paths and improve documentation consistency with the title fix and Kubernetes capitalization.

Also applies to: 38-38, 48-48, 50-51

docs/content/setup/kcp-setup.md (1)

38-39: LGTM! Dex setup simplified with new build workflow.

The changes correctly reflect the new make dex target and the relocated binary at hack/tools/dex.

Also applies to: 55-56

contrib/kcp/Makefile (2)

18-26: LGTM! Build directory structure and PATH reordering are correct.

The new variables properly separate build artifacts (ABS_BUILD_DIR) from downloaded tools (ABS_TOOLS_DIR), and PATH reordering ensures local tools take precedence over system tools for reproducible builds.


40-41: LGTM! UGET invocation for Go modules is correct.

The GO_MODULE=true flag correctly indicates this tool should be fetched as a Go module, and the version parameter is properly specified.

Makefile (5)

130-131: LGTM! Clean target appropriately removes build and tool directories.

The new clean target correctly removes both build artifacts and downloaded tools, providing a complete cleanup mechanism.


182-187: LGTM! Controller-gen download correctly uses UNCOMPRESSED flag and binary pattern.

The target properly specifies UNCOMPRESSED=true for the single-file download and provides a binary pattern to handle the wildcard match.


241-246: LGTM! verify_boilerplate.py download uses correct parameters.

The download uses UNCOMPRESSED=true for the raw Python script and specifies the exact filename as the binary pattern.


249-250: LGTM! Boilerplate verification correctly skips third-party code.

The target appropriately skips the dex directory and hack/uget.sh (which has a different license header as noted in the file).


61-61: No issues found with golangci-lint version format.

The version format at line 61 is correct. The URL pattern prepends 'v' to the version number in the download path, and verification confirms the constructed URL for version 2.1.6 is accessible. This format is appropriate for golangci-lint releases.

hack/uget.sh (6)

16-58: LGTM! Configuration variables are well-documented and have sensible defaults.

The configuration section clearly documents all environment variables and provides appropriate default values.


161-275: LGTM! URL construction and placeholder replacement logic is well-structured.

The URL building functions correctly handle placeholder detection, replacement from system data or provided key-value pairs, and support both live and predetermined replacements. The sorting and deduplication of placeholders ensures consistent checksum keys.


357-417: LGTM! Install and update functions correctly handle versioning and checksums.

The functions properly track installed versions, verify checksums before installation, and support batch checksum updates for all known variants. The version file mechanism prevents unnecessary re-downloads.


462-475: Update mode logic correctly processes all known variants.

The update mode iterates through all known checksums for the binary, downloads each variant, recalculates checksums, and updates the checksum file. Note that line 472 has the same awk injection vulnerability mentioned in an earlier comment.

Verify this comment references the awk injection issue flagged earlier at lines 120-126.


485-488: Verify GOARCH/GOOS addition for Go modules is always correct.

Lines 486-488 automatically add GOARCH and GOOS to the kvString for Go modules to support cross-architecture checksums. Confirm this behavior is always desired, even when the module URL pattern doesn't include architecture placeholders.


347-350: Review comment is inapplicable to this codebase.

The concern about malicious path components in BINARY_PATTERN does not apply here. All uses of BINARY_PATTERN in the Makefile pass hardcoded strings (e.g., controller-gen*, gotestsum) defined as static Makefile variables. The 4th argument to uget.sh is not exposed to external or user-controlled input—it originates exclusively from hardcoded binary name variables. Additionally, the operation executes within an isolated temporary directory, further containing any potential risk.

Likely an incorrect or invalid review comment.

hack/tools.checksums (1)

1-7: Verify that checksums were refreshed via the documented update procedure.

The checksums file format is valid and correctly structured. However, checksum accuracy cannot be verified through format validation alone. Confirm that you ran UGET_UPDATE=true make ... to regenerate these checksums based on the current tool versions before merging.

docs/content/contributing/index.md (1)

20-20: No issues found. Documentation is accurate.

Go 1.24 was released on February 11, 2025. The codebase confirms this requirement consistently across all go.mod files, which specify go 1.24.0 for the main module, SDK, CLI, documentation generators, and contrib modules. The documentation statement aligns with the project's explicit Go version requirement.

Comment thread hack/uget.sh

```bash
./bin/dex serve examples/config-dev.yaml
./hack/tools/dex serve examples/config-dev.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
./hack/tools/dex serve examples/config-dev.yaml
make run-dex

I don't think examples/ exists, or?
Anyhow the run-dex recipe could be used instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

run-dex however uses our own internal development config, whereas the docs mean to instruct the user to use dex's config files. However since the make dex command now builds the dex binary and then deletes the temporary clone, that config-dev.yaml (https://github.com/dexidp/dex/blob/master/examples/config-dev.yaml) is not available anymore.

What would you suggest? Revert the docs to make people continue to manually clone and build and not delete dex, or copy dex's config-dev.yaml into our repo? Or copy it too when building dex (i.e. make our Makefile copy the file)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm.. I think we can handwave the dex configuration and just use the development config.
When people implement kube-bind in their environment they will have to configure and use their OIDC provider anyhow, explicitly requiring the user to configure dex doesn't really add anything IMHO.

On-behalf-of: @SAP christoph.mewes@sap.com

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
hack/uget.sh (1)

173-178: Consider using fixed-string grep to prevent regex injection.

The valueFromPair and setKeyInPairs functions use extended regex (-E) with $key variable interpolation. Although current usage passes only controlled placeholder names, using fixed-string mode (grep -F) would be more defensive and prevent potential regex injection if these functions are ever called with untrusted input.

 uget::url::valueFromPair() {
   local kvString="$1"
   local key="$2"

-  (echo "$kvString" | grep -oE ";$key=([^;]+)" || true) | cut -f2 -d'='
+  (echo "$kvString" | grep -oF ";$key=" || true) | sed 's/^;//' | sed 's/=.*//' | head -1 | xargs -I {} sh -c 'echo "$kvString" | sed -n "s/.*;'$key'=\([^;]*\).*/\1/p"' || true)

Or more simply, parse the kvString directly without grep:

 uget::url::valueFromPair() {
   local kvString="$1"
   local key="$2"
-  (echo "$kvString" | grep -oE ";$key=([^;]+)" || true) | cut -f2 -d'='
+  [[ "$kvString" =~ ;${key}=([^;]+) ]] && echo "${BASH_REMATCH[1]}"
 }

Also applies to: 180-193

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb15ddc and 13ae130.

📒 Files selected for processing (1)
  • hack/uget.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: go-test
  • GitHub Check: lint
  • GitHub Check: go-test-e2e
  • GitHub Check: verify
🔇 Additional comments (3)
hack/uget.sh (3)

120-126: Security fix for awk variable injection is correctly applied.

The previous review flagged shell/awk injection vulnerabilities where $BINARY and $kvString were interpolated directly into awk patterns. The current code properly uses awk's -v flag to safely pass these values as variables while using single-quoted awk scripts. This prevents injection attacks and correctly remediates the prior concern.

Also applies to: 145-145, 472-472


16-16: Solid error handling and resource management practices.

The script correctly uses set -euo pipefail for strict execution, creates and cleans up temporary directories consistently, maintains atomic checksum file updates, and applies proper quoting throughout. Resource cleanup code properly uses rm -rf -- to prevent flag interpretation. Error messages provide adequate context for troubleshooting.

Also applies to: 63-80, 137-154, 382-391


306-320: Go module cross-compilation approach is well-justified.

The use of a dummy module with go mod init and go get to enable cross-compilation of Go binaries is a correct workaround for Go's security restriction documented in golang/go#57485. The explicit GOARCH/GOOS environment variables and the comment explaining the rationale demonstrate solid understanding of Go's build constraints.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13ae130 and 45c2712.

📒 Files selected for processing (1)
  • docs/content/setup/local-setup-with-kind.md (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-22T06:41:37.475Z
Learnt from: mjudeikis
Repo: kube-bind/kube-bind PR: 342
File: docs/content/usage/migration.md:34-37
Timestamp: 2025-10-22T06:41:37.475Z
Learning: In the kube-bind repository documentation and examples, "mangodb" (with group "mangodb.com" and resource "mangodbs") is an intentional fictional example name chosen to avoid referencing real products like MongoDB. It should not be treated as a typo.

Applied to files:

  • docs/content/setup/local-setup-with-kind.md
🪛 LanguageTool
docs/content/setup/local-setup-with-kind.md

[grammar] ~7-~7: Use a hyphen to join words.
Context: ...be-bind/backend * Provides kube-bind compatible backend for MangoDB resources...

(QB_NEW_EN_HYPHEN)

🪛 markdownlint-cli2 (0.18.1)
docs/content/setup/local-setup-with-kind.md

6-6: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


7-7: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


9-9: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: lint
  • GitHub Check: go-test
  • GitHub Check: verify
  • GitHub Check: go-test-e2e

Comment thread docs/content/setup/local-setup-with-kind.md
Comment thread docs/content/setup/local-setup-with-kind.md
On-behalf-of: @SAP christoph.mewes@sap.com
On-behalf-of: @SAP christoph.mewes@sap.com
@xrstf xrstf closed this Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants